<!DOCTYPE html>
<html lang="zh-CN">
<head>
	<meta charset="UTF-8">
	<meta name="apple-mobile-web-app-capable" content="yes">
	<meta name="viewport" content="width=device-width, initial-scale=1.0,minimum-scale=1.0, maximum-scale=1.0, user-scalable=no">
	<meta name="apple-mobile-web-app-status-bar-style" content="black">
	<meta name="format-detection" content="telephone=no">
	<meta name="description" content="">
    <meta name="author" content="">    
	<meta name="keywords" content="玩精灵,财经智库">	
	<title>玩精灵后台</title>	
</head>

	<body>
		<div class="container">
		<!-- 主体部分 -->
			<!-- <div class="containermain"> -->
	
						<!-- 右侧内容 -->
						<!-- <div id="rightcontent"> -->
							<div class="rightcontent">
								<!-- 页面导航 -->
								<div class="righttopnav">
									<a class="index">首页></a><a>栏目管理</a>
								</div>
								<!-- 操作区 -->
								<div class="caozuodiv">
									<div class="content_p caozuo_p">
										<span class="content_inputdiv4"><input id="usertypeinp" type="text" readonly="readonly" value="" name="type" readonly="" placeholder="事件分类" /><i class="icotype"></i>
										<div class="usertype">
											<div class="userli userlied">按作者搜索</div>
											<!-- <div class="userli">添加管理员</div>
											<div class="userli">修改密码</div>
											<div class="userli">添加轮播图</div>
											<div class="userli">删除轮播图</div>
											<div class="userli">添加文章</div>
											<div class="userli">删除文章</div> -->

										</div>
										</span>
									</div>
									<input type="hidden" name="authorSid" id="authorSid">
									<!-- <input class="searchinpu" type="text"  placeholder="用户名"> -->
									<a class="originborbtn usersear">查询</a>
									<a class="originbtn adduser">新建栏目</a>
								</div>

								<!-- 数据table -->
								<div class="contenttable">
									
									<table id="table01" class="table01">
										<!-- <colgroup>
										 <col class="item-list-col0">
										 <col class="item-list-col1">
										 <col class="item-list-col2">
										 <col class="item-list-col3">
										 <col class="item-list-col4">
										 <col class="item-list-col5">
										 <col class="item-list-col6">
										 </colgroup>
										<tr>
											<th>图片</th>
											<th>标题</th>
											<th>地址</th>
											<th>状态</th>
											<th>创建时间</th>
											<th>操作</th>
										</tr>
										<tr>
											<td><img src="../images/111.png"></td>
											<td>五一活动</td>
											<td>http://www.caijingwulin.com/index.html</td>
											<td>已启用</td>	
											<td>2018-03-29</td>
											<td><a class="tab_editor"></a><a class="tab_del"></a></td>
										</tr>									
										<tr>
											<td><img src=""></td>
											<td>五一活动</td>
											<td>http://www.caijingwulin.com/index.html</td>
											<td>已启用</td>	
											<td>2018-03-29</td>
											<td><a class="tab_editor"></a><a class="tab_del"></a></td>
										</tr> -->
									</table>
								</div>

								<!-- 翻页 -->
								<div class="pages">
									
								</div>
							</div>
						
						<!-- 用户编辑框 -->
						<div class="zhezhaodiv"></div>
						<div class="editordiv">
							<!-- 页面导航 -->
								<div class="righttopnav">
									新增/编辑
								</div>

								<!-- 数据table -->
								<div class="contenttable">
									
									<div id="table02">										
										<div class="table_user">
											<label class="add_lable">用户名称</label>
											<input class="table_inp" id="loginName" type="text" name=""/>
										</div>					
										<div class="table_user">
											<label class="add_lable">手机号</label>
											<input class="table_inp" id="phone" type="text" name=""/>
										</div>				
										<!-- <div class="table_user">
											<label class="add_lable">设置权限</label>	
											<label class="labelp"><input type="radio" name="abcd" value="4" checked><i>✓</i>系统管理员</label>	
											<label class="labelp"><input type="radio" name="abcd" value="3"><i>✓</i>运维</label>
											<label class="labelp"><input type="radio" name="abcd" value="2"><i>✓</i>客服</label> 
											<label class="labelp"><input type="radio" name="abcd" value="1"><i>✓</i>管理员</label>
										</div>	 -->
										<div class="table_user">
											<label class="add_lable">状态</label>	
											<label class="labelp"><input type="radio" name="abc" value="Y" checked disabled><i>✓</i>启用</label>
											<label class="labelp"><input type="radio" name="abc" value="N" disabled><i>✓</i>停止</label><br>  
	
										</div>	
										<div class="btns">
											<a class="originbtn adduserbtn">确定</a>
											<a class="whitebtn backbtn">返回</a>
										</div>	
									</div>
								</div>
						</div>
		<!-- 	</div> -->
			
		<!-- </div> -->
<script type="text/javascript" src="js/jquery-1.11.0.min.js"></script> 
<script type="text/javascript" src="js/jquerysession.js"></script>
<script type="text/javascript" charset="utf-8" src="js/jquery.xctips.js"></script>
<script type="text/javascript">
// window.onload=function(){	

 $(document).ready(function() {  
        // val()无参数是取值，有参数是设置  
        // 为了更好的兼容性，将下面的val()设置与input中的placeholder的值设置相同  
        $("input.searchinpu").val("请输入完整专栏标题");  
        textFill($('input.searchinpu'));  
    }); 
var urank = $.session.get("rank");
console.log("banner管理");
	$(".navli").click(function(){
		$(this).addClass('select').siblings().removeClass('select');					
	});
	
//添加新数据
$(".adduser").click(function(){
	console.log("新增专栏");
		window.location.href='special/specialnew.html';
});

//事件分类
$("#usertypeinp").val($('.userlied').html());//默认值
$(".userli").click(function(){
	console.log('分类');
	console.log($(this).html());
	// console.log($(this).parent('.content_p').children('input').val());
	// thisp.children('input').val($(this).html());
	$(this).addClass('userlied').siblings().removeClass('userlied');
		$("#usertypeinp").val($(this).html());
	// 	console.log($("#usertypeinp").val());
})
$(".content_inputdiv4").click(function(){
		$(this).children(".usertype").toggle(300);
	});
//返回
$(".backbtn").click(function(){
	if(ison){
		if(ison){
		ison = false;
		zhezhao(ison);
	}else{
		ison = true;
		zhezhao(ison);
	}
	}
});

//作者列表
	$.ajax({
		type: "get",
		url: url+"author/AllAuthor",
		data:{
			'page': 0,
			'pageSize': 9999999
		},
		success: function(data){
			console.log(data);
			if(data.code=='2000'){				
					var titlelist = data.data.content;
					var titlthtml = [];
					if (titlelist.length ==0) {
						titlthtml='没有作者，请添加作者';
					}else{
						for(var i in titlelist){						
						titlthtml+='<div class="userli" sid="'+titlelist[i].sid+'">'+titlelist[i].name+'</div>';
					 	}
					}
					$('.usertype').html(titlthtml);
					//选择文章
					$(".userli").click(function(){
							console.log('分类');
							$(this).addClass('userlied').siblings().removeClass('userlied');
								$("#usertypeinp").val($(this).html());
								$("#authorSid").val($(this).attr('sid'));
								console.log($("#usertypeinp").val());
						})


			}else{
				
			}
		}
	})

// 专栏列表
var id=0;//序号
var newpage = 0; //当前页面
var pagesize = 10; //每页条数
searchauthor(newpage);
function searchauthor(newpage) {
 console.log('专栏列表');
	$.ajax({
			type: "get",
			url: url+"course/allCourse",
			data:{
				'page': newpage,
				'pageSize': pagesize,
			},
			success: function(data){
				console.log(data);
				if (data.code == '2000') {
					var userlist = data.data.content;//作者列表数据
					var pageable = data.data.pageable; //用户翻页
					var totalElements = data.data.totalElements; //总条数
					var pageNumber = pageable.pageNumber;//当前第几页
					var totalPages = data.data.totalPages;//总页数
					var userhtml = '<colgroup>'
										 +'<col class="item-list-col6">'
										 +'<col class="item-list-col0">'
										 +'<col class="item-list-col1">'
										 +'<col class="item-list-col2">'
										 +'<col class="item-list-col3">'
										 +'<col class="item-list-col4">'
										 +'<col class="item-list-col5">'
										 +'<col class="item-list-col6">'
										 +'</colgroup>'
										+'<tr>'
											+'<th>序号</th>'
											+'<th>专栏标题</th>'
											+'<th>专栏封面</th>'
											+'<th>作者</th>'
											+'<th>专栏类型</th>'
											+'<th>武力值</th>'
											+'<th>查看专栏下课程</th>'
											+'<th>操作</th>'
										+'</tr>';
							for(var i in userlist){
								var usertime = timeStamp2String(parseInt(userlist[i].createdDatetime));
								var usid = userlist[i].sid;
								id++;
								userhtml += '<tr>'+
								            '<td>'+id+'</td>'+
								            '<td>'+userlist[i].courseSubTitle+'</td>'+
											'<td><img src="'+userlist[i].thumbnail+'"></td>'+
											'<td>'+userlist[i].authorName+'</td>'+
											'<td>'+userlist[i].courseType+'</td>'+											
											'<td>'+userlist[i].forceValue+'</td>'+
											'<td class="keclist" sid="'+usid+'" authorSid="'+userlist[i].authorSid+'">查看课程</td>'+											
											'<td><a class="tab_editor" artsid="'+usid+'" sid="'+usid+'"></a><a class="tab_del" sid="'+usid+'"></a></td>'+
											'</tr>';
											
							}
							$("#table01").html('');
							$("#table01").append(userhtml);
							console.log('数据成功加载');

							//编辑banner信息
							$(".tab_editor").click(function(){
								// window.location.href='marketingmar/editorbanner.html?artilcesid='+$(this).attr('artsid')+'&bannersid='+$(this).attr('sid');
								window.location.href='special/specialanewg.html?bannersid='+$(this).attr('sid')+'&artilcesid='+$(this).attr('artsid');
							});
							//查看课程列表
							$('.keclist').click(function() {
								console.log($(this).attr('sid'));
								window.location.href='keclist.html?sid='+$(this).attr('sid')+'&authorSid='+$(this).attr('authorSid');
							})

							// 专题删除事件
							$(".tab_del").click(function(){
								console.log(typeof $(this).attr('sid'));
								console.log($(this).attr('sid'));
								$.ajax({
									type: "post",
									url: url+"course/removeCourse",
									data:{
										'courseSid': $(this).attr('sid'),
									}, 
									success: function(data){
										if (data.code == '2000') {
											alert('删除成功');
											searchauthor(newpage);
										}else{
											console.log('删除失败');
										}
									}
								});
							});

							//翻页
							var pagehtml='';
							var now = pageNumber+1;
							pagehtml = '<a class="pre"><</a>'
									+'<ul class="pagesul">'
										+'<li class="pagesnum thispage">'+now+'</li>'
										+'<li class="pagesnum">总共'+totalPages+'页</li>'
										+'<li class="pagesnum"><input class="pageinp" id="yema" type="tel" oninput="checkNum(this.value)"  placeholder="输入页码" value=""/></li>'
										+'<li class="pagesnum thispage tiaoz">跳转</li>'
									+'</ul>'
									+'<a class="next">></a>';
							$(".pages").html(pagehtml);

							//跳转页码
							$(".tiaoz").click(function(){
								var thispage = $(".pageinp").val(); //输入跳转的页码
								// newpage = parseInt(thispage-1);
								//输入页码不为空
								if(thispage.length!=0 && !isNaN(thispage)){
									console.log("当前输入页面"+thispage);
									if(totalPages+1>thispage>0){
										if(newpage == thispage-1){
											//如果是跳转当前页面,则不跳转，不刷新页面
											console.log('跳转当前页面');
											newpage = thispage-1;
											return false;
										}else{
											//跳转到输入页面
											id = (thispage-1)*pagesize;//跳转页面id起始
											newpage = thispage-1;
											searchauthor(newpage);
										}
										
									}else{
										alert('请输入准确页码');
										$(".pageinp").val('');//清空搜索框
									}
									
								}
								
							});
							//上一页
							$(".pre").click(function(){
								console.log(newpage);
								if(newpage>0){
									//当前页面需要大于0 ，小于总页数
									//如果当前条数少于每页条数时，即最后一页
									console.log('userlist.length'+userlist.length);
									if(userlist.length<pagesize){
										id = id-userlist.length-pagesize;
										searchauthor(newpage-1);
									}else if(userlist.length==pagesize){
										id = id - pagesize*2;
										searchauthor(newpage-1);
									}
								}else{
									alert('没有上一页了');
								}								
							})
							//下一页
							$(".next").click(function(){
								console.log(newpage);
								if(totalPages-1>newpage){
									//当前页面需要小于总页数
									searchauthor(newpage+1);
								}else{
									alert('没有下一页了');
								}
							})

							//遮罩层弹窗							
							zhezhao(ison);
				}
			}
		})
}


//确认
var sid = '';//用户存储用户id
$(".adduserbtn").click(function(){
	console.log('确认');
	if(ison){
		if(ison){
		ison = false;
		zhezhao(ison);
		}else{
			ison = true;
			zhezhao(ison);
		}
	}
	
		console.log(sid);
		$.ajax({
			type: "get",
			url: url+"account/edit",
			data:{
				'sid': sid
			},
			success: function(data){
				console.log(data);
				var useredit = data.data.account;
				if (data.code=='2000') {
					$("#loginName").val(useredit.name);
					$("#phone").val(useredit.mobile);
					$("input[name='abc']:checked").val("Y");

				}else{
					console.log('系统错误');
				}
			}
		})

		if(ison){
			ison = false;
			zhezhao(ison);
		}else{
			ison = true;
			zhezhao(ison);
		}
							

});

$(".usersear").click(function(){
	usersear();
});


// 根据用户名，查询专栏列表

function usersear(){	
	var id=0;//序号
	var newpage = 0; //当前页面
	var pagesize = 10; //每页条数
	var authorSid = String($("#authorSid").val());
	console.log($("#authorSid").val());
	console.log(authorSid);
	if(authorSid.length!=0){
	$.ajax({
		type: "get",
		url: url+"course/listByAuthor",
		data:{
			'authorSid': authorSid,
			'page': newpage,
			'pageSize': pagesize
		},
		success: function(data){
							if (data.code == '2000') {
					var userlist = data.data.content;//作者列表数据
					var pageable = data.data.pageable; //用户翻页
					var totalElements = data.data.totalElements; //总条数
					var pageNumber = pageable.pageNumber;//当前第几页
					var totalPages = data.data.totalPages;//总页数
					var userhtml = '<colgroup>'
										 +'<col class="item-list-col0">'
										 +'<col class="item-list-col0">'
										 +'<col class="item-list-col1">'
										 +'<col class="item-list-col2">'
										 +'<col class="item-list-col3">'
										 +'<col class="item-list-col4">'
										 +'<col class="item-list-col5">'
										 +'<col class="item-list-col6">'
										 +'</colgroup>'
										+'<tr>'
											+'<th>序号</th>'
											+'<th>专栏标题</th>'
											+'<th>专栏封面</th>'
											+'<th>作者</th>'
											+'<th>专栏类型</th>'
											+'<th>武力值</th>'
											+'<th>查看专栏下课程</th>'
											+'<th>操作</th>'
										+'</tr>';
							for(var i in userlist){
								var usertime = timeStamp2String(parseInt(userlist[i].createdDatetime));
								var usid = userlist[i].sid;
								id++;
								userhtml += '<tr>'+
								            '<td>'+id+'</td>'+
								            '<td>'+userlist[i].courseSubTitle+'</td>'+
											'<td><img src="'+userlist[i].thumbnail+'"></td>'+
											'<td>'+userlist[i].authorName+'</td>'+
											'<td>'+userlist[i].courseType+'</td>'+											
											'<td>'+userlist[i].forceValue+'</td>'+
											'<td class="keclist" sid="'+usid+'" authorSid="'+userlist[i].authorSid+'">查看课程</td>'+											
											'<td><a class="tab_editor" artsid="'+usid+'" sid="'+usid+'"></a><a class="tab_del" sid="'+usid+'"></a></td>'+
											'</tr>';
											
							}
							$("#table01").html('');
							$("#table01").append(userhtml);
							console.log('数据成功加载');

							//编辑banner信息
							$(".tab_editor").click(function(){
								// window.location.href='marketingmar/editorbanner.html?artilcesid='+$(this).attr('artsid')+'&bannersid='+$(this).attr('sid');
								window.location.href='special/specialanewg.html?sid='+$(this).attr('sid');
							});
							//查看课程列表
							$('.keclist').click(function() {
								console.log($(this).attr('sid'));
								window.location.href='keclist.html?sid='+$(this).attr('sid')+'&authorSid='+$(this).attr('authorSid');
							})

							// 专题删除事件
							$(".tab_del").click(function(){
								console.log(typeof $(this).attr('sid'));
								console.log($(this).attr('sid'));
								$.ajax({
									type: "post",
									url: url+"course/removeCourse",
									data:{
										'courseSid': $(this).attr('sid'),
									}, 
									success: function(data){
										if (data.code == '2000') {
											xcsoft.success('删除成功',3000);//提示语
											usersear();
										}else{
											xcsoft.error('删除失败',3000);//提示语
										}
									}
								});
							});

							//翻页
							var pagehtml='';
							var now = pageNumber+1;
							pagehtml = '<a class="pre"><</a>'
									+'<ul class="pagesul">'
										+'<li class="pagesnum thispage">'+now+'</li>'
										+'<li class="pagesnum">总共'+totalPages+'页</li>'
										+'<li class="pagesnum"><input class="pageinp" id="yema" type="tel" oninput="checkNum(this.value)"  placeholder="输入页码" value=""/></li>'
										+'<li class="pagesnum thispage tiaoz">跳转</li>'
									+'</ul>'
									+'<a class="next">></a>';
							$(".pages").html(pagehtml);

							//跳转页码
							$(".tiaoz").click(function(){
								var thispage = $(".pageinp").val(); //输入跳转的页码
								// newpage = parseInt(thispage-1);
								//输入页码不为空
								if(thispage.length!=0 && !isNaN(thispage)){
									console.log("当前输入页面"+thispage);
									if(totalPages+1>thispage>0){
										if(newpage == thispage-1){
											//如果是跳转当前页面,则不跳转，不刷新页面
											console.log('跳转当前页面');
											newpage = thispage-1;
											return false;
										}else{
											//跳转到输入页面
											id = (thispage-1)*pagesize;//跳转页面id起始
											newpage = thispage-1;
											usersear(newpage);
										}
										
									}else{
										alert('请输入准确页码');
										$(".pageinp").val('');//清空搜索框
									}
									
								}
								
							});
							//上一页
							$(".pre").click(function(){
								console.log(newpage);
								if(newpage>0){
									//当前页面需要大于0 ，小于总页数
									//如果当前条数少于每页条数时，即最后一页
									console.log('userlist.length'+userlist.length);
									if(userlist.length<pagesize){
										id = id-userlist.length-pagesize;										usersear(newpage-1);
									}else if(userlist.length==pagesize){
										id = id - pagesize*2;
										usersear(newpage-1);
									}
								}else{
									alert('没有上一页了');
								}								
							})
							//下一页
							$(".next").click(function(){
								console.log(newpage);
								if(totalPages-1>newpage){
									//当前页面需要小于总页数
									searchauthor(newpage+1);
								}else{
									alert('没有下一页了');
								}
							})
							//遮罩层弹窗							
							zhezhao(ison);
				}
			
		}
	})
	}else{
		alert("请选择作者");
	}

}

				// 专题列表数据
				// var id = 0;//序号
				// var newpage = 0; //当前页面
				// var pagesize = 6; //每页条数

				// userinfo();暂时不加载数据
				function userinfo(){
				$.ajax({
					type: "get",
					url: url+"banner/showAllBanner",
					success: function(data){
						if(data.code=='2000'){
							var userlist = data.data;//用户列表数据
							// var pageable = data.data.pageable; //用户翻页
							// var totalElements = data.data.totalElements; //总条数
							// var pageNumber = pageable.pageNumber;//当前第几页
							// var totalPages = data.data.totalPages;//总页数
							var userhtml = '<colgroup>'
										 +'<col class="item-list-col0">'
										 // +'<col class="item-list-col1">'
										 // +'<col class="item-list-col2">'
										 // +'<col class="item-list-col3">'
										 +'<col class="item-list-col4">'
										 +'<col class="item-list-col5">'
										 // +'<col class="item-list-col6">'
										 +'</colgroup>'
										+'<tr>'
											+'<th>专栏标题</th>'
											+'<th>专栏封面</th>'
											+'<th>作者</th>'
											+'<th>专栏类型</th>'
											+'<th>武力值</th>'
											+'<th>操作</th>'
										+'</tr>';
							for(var i in userlist){
								var usertime = timeStamp2String(parseInt(userlist[i].createdDatetime));
								var usid = userlist[i].sid;
								//状态
								if( userlist[i].sortBy=='1' ){
									zhuangt ='已启用';
								}else if( userlist[i].sortBy == '2' ){
									zhuangt ='未启用';	
								}else{
									zhuangt = '不明';
								}
								//创建时间								
								// id++;	
								userhtml += '<tr>'+
								            '<td>'+zhuangt+'</td>'+
											'<td><img src="'+userlist[i].imageUrl+'"></td>'+
											'<td>'+userlist[i].title+'</td>'+
											'<td>'+userlist[i].articleSid+'</td>'+											
											'<td>'+zhuangt+'</td>'+
											// '<td>'+timeStamp2String(userlist[i].createdDatetime)+'</td>'+
											'<td><a class="tab_editor" artsid="'+userlist[i].articleSid+'" sid="'+usid+'"></a><a class="tab_del" sid="'+usid+'"></a></td>'+
											'</tr>';
											
							}
							$("#table01").html('');
							$("#table01").append(userhtml);
							console.log('数据成功加载');

							//编辑banner信息
							$(".tab_editor").click(function(){
								// window.location.href='marketingmar/editorbanner.html?artilcesid='+$(this).attr('artsid')+'&bannersid='+$(this).attr('sid');
								window.location.href='special/specialanewg.html?bannersid='+$(this).attr('sid')+'&artilcesid='+$(this).attr('artsid');
							});

							// 专题删除事件
							$(".tab_del").click(function(){
								console.log(typeof $(this).attr('sid'));
								$.ajax({
									type: "post",
									url: url+"course/removeCourse",
									data:{
										'courseSid': $(this).attr('sid'),
									},
									success: function(data){
										if (data.code == '2000') {
											alert('删除成功');
											userinfo();
										}else{
											console.log('删除失败');
										}
									}
								});
							});



							//遮罩层弹窗							
							zhezhao(ison);

						}else{
							console.log('系统错误');
						}
						
					}
				});
		}
		
</script>
<!-- </body>
	</html>